<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="icon" th:href="@{/读书1.jpg}" type="image/jpg" >
    <link rel="stylesheet" href="../static/layui-v2.5.7/layui/css/layui.css" th:href="@{/layui-v2.5.7/layui/css/layui.css}">
    <!--  -->
    <script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
    <script src="../static/layui-v2.5.7/layui/layui.js" th:src="@{/layui-v2.5.7/layui/layui.js}"></script>
    <!--  -->
</head>

<style>

    body{
        background-color: rgb(246,246,246);
        min-width: 1450px;
    }

    .head_div1{
        width:355px;
        height: 30px;
        display: inline-block;
        /* border: 1px solid red; */
        float: right;
        margin: 15px 15px 0px 0px;
        background-color:rgb(57,61,73);
    }

    .head_div1_input1{
        height: 30px;
        width: 300px;
        border-radius: 5px 5px 5px 5px;
        border: none;
        background-color:rgb(232, 232, 232);
        float: left;
    }


    .head_div1_button{
        height: 30px;
        width: 50px;
        border-radius: 5px 5px 5px 5px;
        background-color:rgb(57,61,73);
        border: 1px solid white;
        //font-family: '楷体';
        font-size: 15px;
        line-height: 30px;
        color: white;
        float: right;
    }

    .head_div2{
        float: right;
        display: inline-block;
        margin-right: 15px;
    }

    .head a {
        //color: black !important;
    }

    .div_body{
        //background-color: white;
        /* 这个白边不能去 */
        border: 1px solid white;
        margin:auto;
        height:517px;
        width: 80%;
        margin-top:20px;
    }

    .div_body_div1{
        height:300px;
        width: 200px;
        //border: 1px solid red;
        float:left;
        background-color: white;
    }

    .div_body_div1>a>div{
        height:60px;
        width: 100%;
        //border: 1px solid red;
        line-height:60px;
        text-align:center;
    }

    .div_body_div1>a>div:hover{
        background-color:rgb(240,240,245);
    }

    .div_body_div2{
        height:517px;
        width: 960px;
        //border: 1px solid red;
        float:right;
        background-color: white;
    }
   /*  */
   .div_body_div2_div1{
        height:60px;
        width:95%;
        margin:auto;
        //border:1px solid red;
        background-color:rgb(240,240,245);
        margin-top:60px;
        line-height:60px;
   }

   .div_body_div2_div2{
        //border: 1px solid red;
        height:60px;
        width:95%;
        margin:auto;
        margin-top:60px;
        line-height:60px;
   }

   .div_body_div2_div1_span, .div_body_div2_div2_span, .div_body_div2_div3_span{
        font-size:20px;
        font-weight:700;
        float:left;
   }

   .div_body_div2_div1_span2{
       font-size:20px;
       font-family:"楷体";
       margin-left:10px;
   }

   .div_body_div2_div2_input, .div_body_div2_div1_input, .div_body_div2_div3_input{
       border: 1px solid #;
       font-size:20px;
       font-family:"楷体";
       height:40px;
       width:400px;
       float:left;
       margin-left:10px;
       margin-top:8px;
   }

   .div_body_div2_div3{
        //border: 1px solid red;
        height:60px;
        width:95%;
        margin:auto;
        margin-top:60px;
        line-height:60px;
        background-color:rgb(240,240,245);
   }

   .div_body_div2_div4{
        //border: 1px solid red;
        height:60px;
        width:95%;
        margin:auto;
        margin-top:60px;
   }

   /* */
    .div_page{
        background-color: white;
        /*border: 1px solid red;*/
        margin:0px auto 15px;
        width: 85%;
        height:60px
    }

   /*  */
    .div_foot {
        width: 100%;
        //border: 1px red solid;
        height: 100px;
        background-color: white;
        margin-top:20px;
        background-color: rgb(57,61,73);
    }

    a {
        text-decoration: none;
    }

    .div_foot_div1 {
        /* border: red 1px solid; */
        width: 990px;
        height: 85px;
        display: inline-block;
        position: relative;
        top: 10px;
        left: 240px;
        text-align: center;
        font-size: 12px;
        line-height: 150%;
        font-family: Arial, Verdana, 宋体;
        color:white;
    }

    .div_foot_div1 div {
        margin-top: 10px;
    }

    .div_foot_div1_div1 a {
        margin: 0 10px;
        color:white;
    }

<!--  -->
   .layui-btn{
        float:right;
   }

</style>

<body>

<div class="head">
    <ul class="layui-nav">

        <li class="layui-nav-item">
            <a th:href="@{/index}">
                <i class="layui-icon layui-icon-home"></i>
                首页
            </a>
        </li>

        <li class="layui-nav-item ">
            <a href="">
                <i class="layui-icon layui-icon-notice"></i>
                系统消息
            </a>
        </li>

        <li class="layui-nav-item">
            <a href="javascript:;">
                <i class="layui-icon layui-icon-read"></i>
                文章类型
            </a>
            <dl class="layui-nav-child">
                <!-- 二级菜单 -->
                <dd><a th:href="@{/list/10/1}">Java</a></dd>
                <dd><a th:href="@{/list/11/1}">C++</a></dd>
                <dd><a th:href="@{/list/12/1}">Python</a></dd>
                <dd><a th:href="@{/list/13/1}">JavaScript</a></dd>
                <dd><a th:href="@{/list/14/1}">C语言</a></dd>
                <dd><a th:href="@{/list/15/1}">云计算</a></dd>
            </dl>
        </li>

        <li class="layui-nav-item">
            <a th:href="@{/post}">
                <i class="layui-icon layui-icon-chat"></i>
                论坛
            </a>
        </li>

        <div class="head_div1">
            <form action="/ImagineCommunity/blogSearchList" method="get">
                <input class="head_div1_input1" name="title" placeholder="&nbsp 输 入 你 想 看 的 文 章 话 题">
                <button class="head_div1_button"><i class="layui-icon layui-icon-search" style="font-size: 25px;"></i></button>
            </form>

        </div>

        <div class="head_div2">

            <li class="layui-nav-item">
                <a th:href="@{/friends}">
                    <i class="layui-icon layui-icon-friends"></i>
                    好友列表
                </a>
            </li>

            <li class="layui-nav-item">
                <a><img th:src="${session.user.headImg}" class="layui-nav-img"><span th:text="${session.user.username}">2</span></a>
                <dl class="layui-nav-child">

                    <dd>
                        <a th:href="@{/outLogin(id = ${session.user.id})}">
                            <i class="layui-icon layui-icon-logout"></i>
                            退了
                        </a>
                    </dd>

                </dl>
            </li>

        </div>
    </ul>

</div>

<div class="div_body">

    <div class="div_body_div1">
        <a th:href="@{/personalInformation}"><div>个人资料</div></a>
        <a th:href="@{/updateHead}"><div >头像设置</div></a>
        <a th:href="@{/updatePassWord}"><div style="background-color:rgb(240,240,245);">密码设置</div></a>
        <a th:href="@{/updateUserName}"><div>账号设置</div></a>
        <a th:href="@{/personalBlog}"><div>内容管理</div></a>
    </div>
    <div class="div_body_div2">
            <div class="div_body_div2_div1">
                <span class="div_body_div2_div1_span">现在使用密码:</span>
                <input class="div_body_div2_div1_input" placeholder="请输入你原始的密码" type="password">
            </div>

            <div class="div_body_div2_div2">
                <span class="div_body_div2_div2_span">需要修改名称:</span>
                <input class="div_body_div2_div2_input" placeholder="请输入要修改的密码"  type="password">
            </div>

            <div class="div_body_div2_div3">
                <span class="div_body_div2_div3_span">确认修改名称:</span>
                <input class="div_body_div2_div3_input" placeholder="请确认要修改的密码"  type="password">
            </div>

            <div class="div_body_div2_div4">
                <button type="button" class="layui-btn layui-btn-danger" id="button"><i class='layui-icon layui-icon-set-fill'></i>修改</button>
            </div>
    </div>


</div>

<!-- 底部相同部分 -->
<div th:replace="foot::#foot"></div>

</body>
<!--  -->
<script th:inline="javascript">
    <!-- layui -->
    layui.use('element', function () {
        var element = layui.element;
    });

    //发送信息
    $("#button").click(function () {

        var userId = [[${session.user.id}]];

        var oldPassWord = $(".div_body_div2_div1_input").val();
        layui.use('layer', function () {
            if (oldPassWord == "" || oldPassWord == null) {
                 layer.msg("请输入原密码!");
                 return false;
             }

            //密码验证:必须由字母，数字下划线组成，并且长度为5到12位
            var passwordText = $(".div_body_div2_div2_input").val();
            //创建正则表达式对象
            var passwordPatt = /^\w{5,12}$/;
            //使用test方法验证
            if (!passwordPatt.test(passwordText)) {
                layer.msg("密码名称为5到12位个字符！");
                return false;
            }

            //确认密码：和密码相同
            var passwordTest = $(".div_body_div2_div3_input").val();
            console.log("一、"+passwordTest);

            console.log("二、"+passwordText);
            //和密码相比较
            if (passwordTest != passwordText) {
                layer.msg("两次密码不一致！");
                return false;
            }

            $.ajax({
                url:'/ImagineCommunity/setPassWord',
                data:{userId:userId,
                      oldPassWord:oldPassWord,
                      passWord:passwordText,
                },
                type:'POST',
                success:function(res){
                    if(res.msg == 'no'){
                       layer.msg('原始密码不正确!');
                       return false;
                    }
                    if(res.msg == 'yes'){
                        layer.msg('修改成功!');
                        setTimeout(function(){
                          layer.closeAll();
                          window.location.href = "/ImagineCommunity/updatePassWord";
                        }, 1000);
                    }
                }
            })
        })
    })

    <!-- 浏览器关闭事件,浏览器关闭时向后台发送退出链接 -->
    $(window).unload(function(){
        $.ajax({
            url : "/ImagineCommunity/outLogin?id=[[${session.user.id}]]",
        })
    });

</script>
</html>